﻿#region Using Statements
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

#endregion

#region COPYRIGHT

/*
    Copyright (c) 2008, 2009, 2010 
        Roland Rosenkranz (Glatzemann@email.de)
*/

#endregion

#region LICENSE

/*
    This file is part of starLiGHT.Collision.

    starLiGHT.Collision is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    starLiGHT.Collision is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with starLiGHT.Collision.  If not, see <http://www.gnu.org/licenses/>.

    
    ADDITIONAL (commercial) LICENSES for starLiGHT.Collision are available on request.
*/

#endregion

#region Box2D Copyright
/*
* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty.  In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#endregion

#region Version Stuff
// **************[ starLiGHT.Engine SVN ]**********************
// * $Rev:: 1486                  $:  Revision of last commit *
// * $Author:: glatzemann         $:  Author of last commit   *
// * $Date:: 2010-10-08 15:55:47 #$:  Date of last commit     *
// ************************************************************

// **************[ Box2D-Repository Info ]*********************
// Header-File: http://code.google.com/p/box2d/source/browse/trunk/Box2D/Box2D/Collision/Shapes/b2Shape.h
// Revision   : r109
// Change-Date: 2010-05-31
//
// Source-File: n/a
// Revision   : n/a
// Change-Date: n/a
//
// Status     : Finished!
#endregion

namespace starLiGHT.Physic.TwoD
{
    /// <summary>This holds the mass data computed for a shape.</summary>
    public struct MassData
    {
        /// <summary>The mass of the shape, usually in kilograms.</summary>
        public float mass;

        /// <summary>The position of the shape's centroid relative to the shape's origin.</summary>
        public Vector2 center;

        /// <summary>The rotational inertia of the shape about the local origin.</summary>
        public float I;
    };

    /// <summary>The various collision shape types supported by Box2D.</summary>
    [Flags]
    public enum ShapeType
    {
        UNKNOWN = -1,
        CIRCLE = 0,
        EDGE = 1,
        POLYGON = 2,
        LOOP = 3,
        FLUID = 4,
        SHAPE_TYPE_COUNT = 5,
    };

    /// <summary>
    /// A shape is used for collision detection. You can create a shape however you like.
    /// Shapes used for simulation in World are created automatically when a Fixture
    /// is created. Shapes may encapsulate a one or more child shapes.
    /// </summary>
    public abstract class Shape
    {
        public ShapeType m_type;
        public float m_radius;

	    public Shape() 
        {
            m_type = ShapeType.UNKNOWN;
        }

        public abstract Shape Clone();

        /// <summary>Get the type of this shape. You can use this to down cast to the concrete shape.</summary>
	    /// <returns>the shape type.</returns>
        new public ShapeType GetType()
        {
            return m_type;
        }

        /// <summary>Get the number of child primitives.</summary>
        public abstract int GetChildCount();

        /// <summary>Test a point for containment in this shape. This only works for convex shapes.</summary>
        /// <param name="p">point in world coordinates</param>
        /// <param name="xf">the shape world transform</param>
	    public abstract bool TestPoint(ref Transform xf, Vector2 p);

        /// <summary>Cast a ray against a child shape. </summary>
        /// <param name="output">the ray-cast results. </param> 
        /// <param name="input">the ray-cast input parameters. </param> 
        /// <param name="transform">the transform to be applied to the shape. </param> 
        /// <param name="childIndex">the child shape index</param>
        public abstract bool RayCast(out RayCastOutput output, ref RayCastInput input, ref Transform transform, int childIndex);

        /// <summary>Given a transform, compute the associated axis aligned bounding box for a child shape.</summary>
        /// <param name="aabb">returns the axis aligned box.</param> 
        /// <param name="xf">the world transform of the shape.</param> 
        /// <param name="childIndex">the child shape index</param>
        public abstract void ComputeAABB(out AABB aabb, ref Transform xf, int childIndex);

        /// <summary>Compute the mass properties of this shape using its dimensions and density.
        /// The inertia tensor is computed about the local origin.</summary>
        /// <param name="massData">returns the mass data for this shape.</param> 
        /// <param name="density">the density in kilograms per meter squared.</param> 
	    public abstract void ComputeMass(out MassData massData, float density);
    };
}
